package com.dotto.atos.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.dotto.atos.R;
import com.dotto.atos.activity.HomeActivity;
import com.dotto.atos.utils.MessageUtil;

public class MenuFragment extends Fragment {

	public static final String TAG = "MenuFragment";
	private View fragmentView;
	private Activity mActivity;
	@SuppressWarnings("unused")
	private MenuFragment instance;

	@SuppressWarnings("unused")
	private MessageUtil messageUtil;

	private Button menuItemOnlinePayment;
	private Button menuItemCardApp;
	private Button menuItemRefusalPanel;
	private Button menuItemBluewiki;
	private Button menuItemAnnouncement;
	private Button menuItemReports;
	private Button menuItemExit;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (fragmentView == null) {
			fragmentView = inflater.inflate(R.layout.fragment_menu, container,
					false);
		} else {
			((ViewGroup) fragmentView.getParent()).removeView(fragmentView);
		}
		mActivity = this.getActivity();
		instance = this;
		messageUtil = new MessageUtil(mActivity);
		initView();
		return fragmentView;
	}

	public void initView() {
		if (fragmentView != null) {
			menuItemOnlinePayment = (Button) fragmentView
					.findViewById(R.id.menu_item_online_payment);
			menuItemOnlinePayment.setOnClickListener(onClickOnlinePayment);

			menuItemCardApp = (Button) fragmentView
					.findViewById(R.id.menu_item_card_app);
			menuItemCardApp.setOnClickListener(onClickCardApp);

			menuItemRefusalPanel = (Button) fragmentView
					.findViewById(R.id.menu_item_refusal_panel);
			menuItemRefusalPanel.setOnClickListener(onClickRefusalPanel);

			menuItemBluewiki = (Button) fragmentView
					.findViewById(R.id.menu_item_bluewiki);
			menuItemBluewiki.setOnClickListener(onClickBluewiki);

			menuItemAnnouncement = (Button) fragmentView
					.findViewById(R.id.menu_item_announcement);
			menuItemAnnouncement.setOnClickListener(onClickAnnouncement);

			menuItemReports = (Button) fragmentView
					.findViewById(R.id.menu_item_reports);
			menuItemReports.setOnClickListener(onClickReports);

			menuItemExit = (Button) fragmentView
					.findViewById(R.id.menu_item_exit);
			menuItemExit.setOnClickListener(onClickExit);

		}
	}

	private OnClickListener onClickOnlinePayment = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showOnlinePaymentFragment(1);
		}
	};

	private OnClickListener onClickCardApp = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showCardApplicationMenuFragment(1);
		}
	};

	private OnClickListener onClickRefusalPanel = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showRefusalPanelFragment(1);
		}
	};

	private OnClickListener onClickBluewiki = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showBlueWikiFragment(1);
		}
	};

	private OnClickListener onClickAnnouncement = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showAnnouncementsFragment(1);
		}
	};

	private OnClickListener onClickReports = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showReportFragment(1);
		}
	};

	private OnClickListener onClickExit = new OnClickListener() {
		@Override
		public void onClick(View v) {
			HomeActivity.instance.showBackStack(LoginFragment.TAG);
		}
	};
}
